﻿using System;
using System.Linq;
using FrameWork.Services;
using System.Windows.Data;
using System.Globalization;
using FrameWork.Data.Mapping;

namespace AncheStart.Converter
{
    public class IndexToIntConverter : IValueConverter
    {
        /// <summary>
        /// 读取配置 一个工步有那些列可以见 设置是否可见
        /// </summary>
        /// <param name="stepIndex"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object stepIndex, Type targetType, object parameter, CultureInfo culture)
        {
            var index = (int)stepIndex;
            var columnCode = (string)parameter;
            //新增启用判定
            StepConfig stepConfig = GlobalConstant.StepConfigs.Where(P => P.ColumnCode == columnCode && P.StepInfoId == index&&P.Enabled==true).FirstOrDefault();
            return stepConfig == null ? 0 : (int)stepConfig.ColumnType;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var data = (bool)value;
            if (data)
            {
                return System.Convert.ToInt32(parameter);
            }
            return -1;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}